#region

using VinhSon.Intranet.Bussiness;
using VinhSon.Intranet.IRepository;
using VinhSon.Intranet.Repository;

#endregion

namespace VinhSon.Intranet.Models
{
    public class UnitOfWork
    {
        #region Context

        protected readonly VinhSonContext Context = new VinhSonContext();

        public void Save()
        {
            Context.SaveChanges();
        }

        #endregion

        #region Repository fields

        private IPermissionRepository _PermissionRepository;

        private IRoleRepository _RoleRepository;

        private IUserGroupRepository _UserGroupRepository;

        private IUserRepository _UserRepository;

        #endregion

        #region Repository properties

        public IPermissionRepository PermissionRepository
        {
            get
            {
                return _PermissionRepository ?? (_PermissionRepository = new PermissionRepository(Context));
            }
        }

        public IRoleRepository RoleRepository
        {
            get
            {
                return _RoleRepository ?? (_RoleRepository = new RoleRepository(Context));
            }
        }

        public IUserRepository UserRepository
        {
            get
            {
                return _UserRepository ?? (_UserRepository = new UserRepository(Context));
            }
        }

        public IUserGroupRepository UserGroupRepository
        {
            get
            {
                return _UserGroupRepository ?? (_UserGroupRepository = new UserGroupRepository(Context));
            }
        }

        #endregion
    }
}
